package com.leimo.controller;

import com.github.binarywang.wxpay.exception.WxPayException;

import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.util.HashMap;
import java.util.Map;

/**
 * controller增强器
 *
 * @author 段誉
 * @create 2019-04-19 13:31
 */
@RestControllerAdvice
public class ControllerAdvice {
  /**
   * 运行时异常
   * @param e
   * @return
   */
  @ExceptionHandler(RuntimeException.class)
  public Map<String, Object> runtimeException(RuntimeException e) {
    Map<String, Object> res = new HashMap<>(3);
    res.put("code", 13000);
    res.put("msg", e.getMessage());
    e.printStackTrace();
    return res;
  }

  /**
   * 微信支付异常
   * @param e
   * @return
   */
  @ExceptionHandler(WxPayException.class)
  public Map<String, Object> runtimeException(WxPayException e) {
    Map<String, Object> res = new HashMap<>(3);
    res.put("code", 14000);
    res.put("msg", e.getMessage());
    e.printStackTrace();
    return res;
  }
}
